import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;


public class webKeywords {
	
	@Test
	public void KDF2(){
		WebDriver myD = new FirefoxDriver();
		navigateBrowser(myD, "http://www.kayak.com");
		enterText(myD, "//input[@id='wherebox']", "Midway (MDW) - Chicago, IL");
		selectList(myD, "//select[@id='rooms']", "5 rooms");
		checkBox(myD, "//input[@id='cbTRAVELOCITYQ320_US_HFDCMP2']");
		myD.quit();
	}

	
	public void enterText(WebDriver driver, String xPath, String data){
		//		Purpose: Enter Text into a edit field
		//		I/P:driver, xPath, Data
		//		O/P:Nil
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		driver.findElement(By.xpath(xPath)).clear();
		driver.findElement(By.xpath(xPath)).sendKeys(data);
	}
	
	public String readText(WebDriver driver, String xPath){
		//		Purpose: Read Text into a edit field
		//		I/P:driver, xPath
		//		O/P:Data
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		return driver.findElement(By.xpath(xPath)).getText();
	}
	
	public void clickElement(WebDriver driver, String xPath){
		//		Purpose: Click any element on the AUT
		//		I/P:driver, xPath
		//		O/P:Nil
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		driver.findElement(By.xpath(xPath)).click();
		driver.findElement(By.xpath(xPath)).sendKeys("\n");
	}
	
	public void selectList(WebDriver driver, String xPath, String data){
		//		Purpose: Select from a dropdown list
		//		I/P:driver, xPath, data
		//		O/P:Nil
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		Select myDD = new Select(driver.findElement(By.xpath(xPath)));
		myDD.selectByVisibleText(data);
		myDD = null;
	}
	
	public void checkBox(WebDriver driver, String xPath){
		//		Purpose: Check a checkbox
		//		I/P:driver, xPath, data
		//		O/P:Nil
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		// Is it checked
		if(driver.findElement(By.xpath(xPath)).getAttribute("checked").equalsIgnoreCase("checked")){
			//Then dont do anything
		} else {
			driver.findElement(By.xpath(xPath)).click();
		}
	}


//	uncheckBox
//	selectRadio
	
	public void navigateBrowser(WebDriver driver, String data){
		//		Purpose: Navigate a browser to a URL
		//		I/P:driver, data
		//		O/P:Nil
		//		CreatedBy:SelA16 Batch
		//		When:9/11/12
		//		EditedBy:Karthik
		//		When:9/11/12
		// Is it checked
		driver.navigate().to(data);
	}
}
